<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function template integer_sort</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Boost.Sort">
<link rel="up" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html" title="Header &lt;boost/sort/spreadsort/integer_sort.hpp&gt;">
<link rel="prev" href="integer_sort_idm1967.html" title="Function template integer_sort">
<link rel="next" href="integer_sort_idm2096.html" title="Function template integer_sort">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="integer_sort_idm1967.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer_sort_idm2096.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.sort.spreadsort.integer_sort_idm2021"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Function template integer_sort</span></h2>
<p>boost::sort::spreadsort::integer_sort — Integer sort algorithm using random access iterators with both right-shift and user-defined comparison operator. (All variants fall back to <code class="computeroutput">boost::sort::pdqsort</code> if the data size is too small, &lt; <code class="computeroutput">detail::min_sort_size</code>). </p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html" title="Header &lt;boost/sort/spreadsort/integer_sort.hpp&gt;">boost/sort/spreadsort/integer_sort.hpp</a>&gt;

</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> RandomAccessIter<span class="special">,</span> <span class="keyword">typename</span> Right_shift<span class="special">,</span> <span class="keyword">typename</span> Compare<span class="special">&gt;</span> 
  <span class="keyword">void</span> <span class="identifier">integer_sort</span><span class="special">(</span><span class="identifier">RandomAccessIter</span> first<span class="special">,</span> <span class="identifier">RandomAccessIter</span> last<span class="special">,</span> 
                    <span class="identifier">Right_shift</span> shift<span class="special">,</span> <span class="identifier">Compare</span> comp<span class="special">)</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idm2705"></a><h2>Description</h2>
<p><code class="computeroutput">integer_sort</code> is a fast templated in-place hybrid radix/comparison algorithm, which in testing tends to be roughly 50% to 2X faster than <code class="computeroutput">std::sort</code> for large tests (&gt;=100kB).<br>
Worst-case performance is <span class="emphasis"><em> O(N * (lg(range)/s + s)) </em></span>, so <code class="computeroutput">integer_sort</code> is asymptotically faster than pure comparison-based algorithms. <code class="computeroutput">s</code> is <code class="computeroutput">max_splits</code>, which defaults to 11, so its worst-case with default settings for 32-bit integers is <span class="emphasis"><em> O(N * ((32/11) </em></span> slow radix-based iterations fast comparison-based iterations).<br>
<br>
Some performance plots of runtime vs. n and log(range) are provided:<br>
 <a href="../../../../../doc/graph/windows_integer_sort.htm" target="_top">windows_integer_sort</a> <br>
 <a href="../../../../../doc/graph/osx_integer_sort.htm" target="_top">osx_integer_sort</a></p>
<p>





</p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Throwing an exception may cause data loss. This will also throw if a small vector resize throws, in which case there will be no data loss. </p></td></tr>
</table></div>
<p>
</p>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Invalid arguments cause undefined behaviour. </p></td></tr>
</table></div>
<p>
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p><code class="computeroutput">spreadsort</code> function provides a wrapper that calls the fastest sorting algorithm available for a data type, enabling faster generic-programming.</p></td></tr>
</table></div>
<p>
</p>
<p>The lesser of <span class="emphasis"><em> O(N*log(N)) </em></span> comparisons and <span class="emphasis"><em> O(N*log(K/S + S)) </em></span>operations worst-case, where: </p>
<p>

</p>
<p>* N is <code class="computeroutput">last</code> - <code class="computeroutput">first</code>, </p>
<p>

</p>
<p>* K is the log of the range in bits (32 for 32-bit integers using their full range), </p>
<p>

</p>
<p>* S is a constant called max_splits, defaulting to 11 (except for strings where it is the log of the character size). </p>
<p>

</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">comp</code></span></p></td>
<td><p>A binary functor that returns whether the first element passed to it should go before the second in order.</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">first</code></span></p></td>
<td><p>Iterator pointer to first element. </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">last</code></span></p></td>
<td><p>Iterator pointing to one beyond the end of data. </p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">shift</code></span></p></td>
<td><p>Functor that returns the result of shifting the value_type right a specified number of bits. </p></td>
</tr>
</tbody>
</table></div></td>
</tr>
<tr>
<td><p><span class="term">Requires:</span></p></td>
<td><p>[<code class="computeroutput">first</code>, <code class="computeroutput">last</code>) is a valid range. </p></td>
</tr>
<tr>
<td><p><span class="term">Requires:</span></p></td>
<td><p><code class="computeroutput">RandomAccessIter</code> <code class="computeroutput">value_type</code> is mutable. </p></td>
</tr>
<tr>
<td><p><span class="term">Postconditions:</span></p></td>
<td><p>The elements in the range [<code class="computeroutput">first</code>, <code class="computeroutput">last</code>) are sorted in ascending order.</p></td>
</tr>
<tr>
<td><p><span class="term">Returns:</span></p></td>
<td><p><code class="computeroutput">void</code>.</p></td>
</tr>
<tr>
<td><p><span class="term">Throws:</span></p></td>
<td>std::exception Propagates exceptions if any of the element comparisons, the element swaps (or moves), the right shift, subtraction of right-shifted elements, functors, or any operations on iterators throw.</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014-2017 Steven
      Ross, Francisco Tapia, Orson Peters<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="integer_sort_idm1967.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../header/boost/sort/spreadsort/integer_sort_hpp.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer_sort_idm2096.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
